home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / RELEASE.ZIP / sub_arctic / anim / transition.java < prev   
Encoding:
Java Source  |  1996-10-04  |  7.1 KB  |  229 lines

  1. package sub_arctic.anim;
  2. import sub_arctic.lib.interactor;
  3. import sub_arctic.input.event;
  4.  
  5. /**
  6.  * Class that implements the transitions, just like in the paper 
  7.  * (Hudson & Stasko, UIST '93) and in artkit.<p>
  8.  *
  9.  * @author Ian Smith
  10.  */
  11. public class transition {
  12.  
  13.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  14.    
  15.   /** Interactor we are operating on.  */
  16.   protected animatable _target;
  17.  
  18.   /**
  19.    * Retrieve the interactor we are operating on.
  20.    * @return animatable the target object for this animation.
  21.    */
  22.   public animatable target() { return _target;};
  23.  
  24.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  25.    
  26.   /** Time interval we are going on. */
  27.   protected time_interval _interval;
  28.  
  29.   /**
  30.    * Retrieve the time interval over which we are operating.
  31.    * @return time_interval the time interval for this transition
  32.    */
  33.   public time_interval interval() { return _interval;};
  34.  
  35.   /**
  36.    * This function sets the time interval for this transition. In
  37.    * general, it is an <b>extremely</b> bad idea for user level
  38.    * code to be manipulating the transitions timing information
  39.    * after the transition has been created.  It is quite likely that
  40.    * unless you understand exactly how the animation system's scheduling
  41.    * works, you will hose yourself if you try to manipulate this while 
  42.    * the transition is running.<P>
  43.    * 
  44.    * This function has
  45.    * been made protected so subclasses of transition can use it, but
  46.    * in general user level code cannot.
  47.    * 
  48.    * @param time_interval t the new time interval to use for this transition
  49.    */
  50.   public void set_interval(time_interval t) { _interval=t;}
  51.  
  52.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  53.    
  54.   /**
  55.    * The trajectory we are using.
  56.    */
  57.   protected trajectory _traj;
  58.  
  59.   /**
  60.    * Retrieve the trajectory for this object.
  61.    * @return trajectory the trajectory over which the animation happens
  62.    */
  63.   public trajectory traj() { return _traj;};
  64.  
  65.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  66.    
  67.   /**
  68.    * Build a transition, given a target animatable, a time interval,
  69.    * and a trajectory.<p>
  70.    * 
  71.    * @param animatable i the target of the animation or transition
  72.    * @param time_interval t the time interval over which this transition occurs
  73.    * @param trajectory t the trajectory over which this transition is mapped
  74.    */
  75.   public transition(animatable i, time_interval t,
  76.             trajectory j) {
  77.     _target=i;
  78.     _interval=t;
  79.     _traj=j;
  80.   }
  81.  
  82.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  83.    
  84.   /**
  85.    * This lets the world know that we have seen a time that is larger
  86.    * than our end.
  87.    */
  88.   protected boolean _finished;
  89.  
  90.   /**
  91.    * Are we done? (Has time passed us by...).
  92.    * @return boolean returns true if this transition has been completed
  93.    */
  94.   public boolean finished() { return _finished;};
  95.  
  96.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  97.    
  98.   /** 
  99.    * What was the last time seen? This function is usually used by
  100.    * code trying to figure out what time interval is "next".
  101.    *
  102.    * @return double the last time (in milliseconds) that we have dealt with 
  103.    */
  104.   public double last_time() { return _last_time;};
  105.  
  106.   /**
  107.    * Store the last time seen.
  108.    */
  109.   protected double _last_time;
  110.  
  111.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  112.    
  113.   /**
  114.    * Start a transition. This is where the work gets done of calling the
  115.    * start_transition function on the interactor.<p>
  116.    * 
  117.    * @param event e the animation event that caused things to get going
  118.    * @param Object user_info the object passed to the animation agent when 
  119.    *                         the animatable joined its focus set
  120.    */
  121.   public void start(event e,Object user_info) {
  122.     Object result;
  123.  
  124.     /* set the last time seen */
  125.     _last_time=0.0;
  126.  
  127.     /* compute the result using the trajectory */
  128.     if (traj()==null) {
  129.       result=null;
  130.     } else {
  131.       result=traj().object_for_parm(0.0);
  132.     }
  133.  
  134.     /* make the call to start him */
  135.     target().start_transition(this, traj(), 0.0, result, e, user_info);
  136.   }
  137.  
  138.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  139.    
  140.   /**
  141.    * Perform a step... this sends the transition_step message to the
  142.    * interactor.<p>
  143.    * 
  144.    * @param event e the animation event for this step
  145.    * @param Object user_info the object passed to the animation agent when 
  146.    *                         the animatable joined its focus set
  147.    * @param long current_time the time it is "now" for this time step
  148.    */
  149.   public void step(event e, Object user_info, long current_time) {
  150.     Object start_result, end_result;
  151.     double c_time;
  152.     time_interval i=interval();
  153.     long diff_time;
  154.  
  155.     /* how far past the start are we*/
  156.     diff_time=current_time-(i.start_time());
  157.  
  158.     /* are we past the end or at it?*/
  159.     if (current_time>=i.end_time()) {
  160.       /* set the flag that we are finished */
  161.       _finished=true;
  162.       return;
  163.     }
  164.  
  165.     /* compute the actual time as a real */
  166.     c_time=(double)diff_time/((double)(i.duration()));
  167.  
  168.     /* now compute the two objects via the trajectory */
  169.     if (traj()==null) {
  170.       start_result=null;
  171.       end_result=null;
  172.     } else {
  173.       start_result=traj().object_for_parm(_last_time);
  174.       end_result=traj().object_for_parm(c_time);
  175.     }
  176.  
  177.     /* send the message to the interactor */
  178.     target().transition_step(this, traj(), _last_time, start_result,
  179.                  c_time, end_result, e, user_info);
  180.  
  181.     /* now reset what time we have seen */
  182.     _last_time=c_time;
  183.   }
  184.  
  185.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  186.    
  187.   /**
  188.    * Send the end message to the interactor.<p>
  189.    *
  190.    * @param event e the animation event for this step
  191.    * @param Object user_info the object passed to the animation agent when 
  192.    *                         the animatable joined its focus set
  193.    */
  194.   public void end(event e, Object user_info) {
  195.     Object start_result, end_result;
  196.  
  197.     /* compute the two objects via the trajectory */
  198.     if (traj()==null) {
  199.       start_result=null;
  200.       end_result=null;
  201.     } else {
  202.       start_result=traj().object_for_parm(_last_time);
  203.       end_result=traj().object_for_parm(1.0);
  204.     }
  205.  
  206.     /* send the message to the interactor */
  207.     target().end_transition(this, traj(), _last_time, start_result,
  208.                 1.0, end_result, e, user_info);
  209.   }
  210.  
  211.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  212. }
  213. /*=========================== COPYRIGHT NOTICE ===========================
  214.  
  215. This file is part of the subArctic user interface toolkit.
  216.  
  217. Copyright (c) 1996 Scott Hudson and Ian Smith
  218. All rights reserved.
  219.  
  220. The subArctic system is freely available for most uses under the terms
  221. and conditions described in 
  222.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  223. and appearing in full in the lib/interactor.java source file.
  224.  
  225. The current release and additional information about this software can be 
  226. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  227.  
  228. ========================================================================*/
  229.